package cn.zn.modules.budget.cur.controller;

import cn.zn.framework.common.utils.PageInUtils;
import cn.zn.framework.common.utils.PageUtils;
import cn.zn.framework.common.utils.R;
import cn.zn.modules.budget.cur.entity.TBudgetInEntity;
import cn.zn.modules.budget.cur.service.TBudgetInService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;


/**
 * 预算分配
 *
 * @author zn
 * @email zhunahao@qq.com
 * @date 2019-12-10 14:27:52
 */
@RestController
@RequestMapping("budget/tbudgetin")
public class TBudgetInController {

    @Autowired
    private TBudgetInService tBudgetInService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("budget:tbudgetin:list")
    public R list(PageInUtils<TBudgetInEntity> pageIn) {

        TBudgetInEntity tBudgetIn = new TBudgetInEntity();
        PageUtils pageUtils = tBudgetInService.queryPage(tBudgetIn, pageIn.getPageObj());

        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("budget:tbudgetin:info")
    public R info(@PathVariable("id") String id) {
            TBudgetInEntity tBudgetIn = tBudgetInService.getById(id);

        return R.ok().put("tBudgetIn", tBudgetIn);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("budget:tbudgetin:save")
    public R save(@RequestBody TBudgetInEntity tBudgetIn) {
            tBudgetInService.save(tBudgetIn);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("budget:tbudgetin:update")
    public R update(@RequestBody TBudgetInEntity tBudgetIn) {
            tBudgetInService.updateById(tBudgetIn);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("budget:tbudgetin:delete")
    public R delete(@RequestBody String[] ids) {
            tBudgetInService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
